import { contextBridge, ipcRenderer } from 'electron'

contextBridge.exposeInMainWorld('electron', {
  // Home
  closeWindow: () => ipcRenderer.send('close-window'),
  minWindow: () => ipcRenderer.send('min-window'),
  // Setting传输数据
  getMessage_Setting1: () => ipcRenderer.invoke('get-message-setting1'),
  getMessage_Setting2: () => ipcRenderer.invoke('get-message-setting2'),
  saveRoom: (data) => ipcRenderer.invoke('save-room', data),
  getDataFiles: (roomId) => ipcRenderer.invoke('get-room-list', roomId),
  deleteFile: (roomId) => ipcRenderer.invoke('delete-room', roomId),
  changeInfo: (data) => ipcRenderer.send('changeInfo-from-console', data),
  // 创建窗口
  createBackWindow: () => ipcRenderer.send('create-back-window'),
  backFullScreen: () => ipcRenderer.send('back-full-screen'),
  backNoFullScreen: () => ipcRenderer.send('back-noFull-screen'),
  getMessageToBack: () => ipcRenderer.send('get-message-toBack'),
  getMainProcessVariable: async () => {
    const response = await ipcRenderer.invoke('getMainProcessVariable')
    return response
  },
  // 创建时间窗口
  createTimeWindow: () => ipcRenderer.send('create-time-window'),
  // 控制时间
  stopOrStartShowTime: () => ipcRenderer.send('stopOrStart-show-time'),
  timeFullScreen: () => ipcRenderer.send('time-full-screen'),
  timeNoFullScreen: () => ipcRenderer.send('time-noFull-screen'),
  reqMessageFromConsole: () => ipcRenderer.send('reqMessage-from-console'),
  resBackToMain: (data) => ipcRenderer.send('resMessage-back-main', data),
  timeToTime: (data) => ipcRenderer.send('time-from-console', data),
  // 添加监听器
  on: (channel, callback) => {
    const validChannels = [
      'stopOrStart-show-time',
      'reqMessage-from-console',
      'reqMessage-to-console',
      'resMessage-to-time',
      'resMessage-to-back',
      'changeInfo-to-time',
      'time-to-time',
      'resMessage-to-back'
      // 其他需要监听的频道...
    ]
    if (validChannels.includes(channel)) {
      ipcRenderer.on(channel, (event, ...args) => callback(...args))
    }
  }
})
